package com.lhf.userservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhf.common.util.Result;
import com.lhf.userservice.entity.FvsSysPer;
import com.lhf.userservice.service.FvsSysPerService;
import com.lhf.userservice.vo.FvsSysPerVO;
import com.lhf.userservice.vo.PerCascaderVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.List;
import java.util.Map;

/**
 * 权限(FvsSysPer)表控制层
 *
 * @author liuhf
 * @since 2021-03-30 08:46:35
 */
@RestController
@RequestMapping("/fvsSysPer")
public class FvsSysPerController {
    /**
     * 服务对象
     */
    @Resource
    private FvsSysPerService fvsSysPerService;

    /**
     * 分页查询所有数据
     *
     * @param page      分页对象
     * @param fvsSysPer 查询实体
     * @return 所有数据
     */
    @GetMapping("selectAll")
    public Result<Page<FvsSysPerVO>> selectAll(Page<FvsSysPer> page, FvsSysPer fvsSysPer) {
        return Result.success(this.fvsSysPerService.selectAll(page, fvsSysPer));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne/{id}")
    public Result<FvsSysPer> selectOne(@PathVariable Serializable id) {
        return Result.success(this.fvsSysPerService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param fvsSysPer 实体对象
     * @return 新增结果
     */
    @PostMapping("save")
    public Result<Boolean> insert(@RequestBody FvsSysPer fvsSysPer) {
        return Result.success(this.fvsSysPerService.save(fvsSysPer));
    }

    /**
     * 修改数据
     *
     * @param fvsSysPer 实体对象
     * @return 修改结果
     */
    @PutMapping("modify")
    public Result<Boolean> update(@RequestBody FvsSysPer fvsSysPer) {
        return Result.success(this.fvsSysPerService.updateById(fvsSysPer));
    }

    /**
     * 删除数据
     *
     * @param pid 权限id
     * @return 删除结果
     */
    @DeleteMapping("del/{pid}")
    public Result<Boolean> delete(@PathVariable Long pid) {
        return Result.success(this.fvsSysPerService.removeById(pid));
    }

    /**
     * 查询角色所有权限
     *
     * @param rid
     * @return
     */
    @GetMapping("/findPerByRid/{rid}")
    public Result<List<FvsSysPerVO>> findPerByRid(@PathVariable Long rid) {
        return Result.success(this.fvsSysPerService.findPerByRid(rid));
    }

    /**
     * 查询用户权限菜单
     *
     * @param uid
     * @return
     */
    @GetMapping("findPerByUid/{uid}")
    public Result<Map<String, List>> findPerByUid(@PathVariable Long uid) {
        return Result.success(this.fvsSysPerService.findPerAndRoute(uid, 0L));
    }


    /**
     * 查询权限级联选择器内容
     *
     * @param parent
     * @return
     */
    @GetMapping("/findPerCascader/{parent}")
    public Result<List<PerCascaderVo>> findPerCascaderByParent(@PathVariable Long parent) {
        return Result.success(this.fvsSysPerService.findPerCascaderByParent(parent));
    }
}
